package com.example.controller;



import com.example.pojo.Result;
import com.example.utils.AliyunOSSOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;


@RestController
public class UploadController {

//    /**
//     * 上传文件 -本地存储方式
//     */
//    @PostMapping("/upload")
//    public Result upload(String username, Integer age , MultipartFile file) throws Exception {
//
//        if(!file.isEmpty()){
//            //路径被我删了，路径名好像不能带中文。
//            file.transferTo(new File("C:\\Users\\86158\\Desktop\\ob_整理文件测试\\" + file.getOriginalFilename()));
//        }
//        return Result.success();
//    }
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
       String url= aliyunOSSOperator.upload(file.getBytes(), file.getOriginalFilename());
       return Result.success(url);
    }



}